#!/usr/bin/env python
# -*- coding: UTF-8 -*-
from flask import request

import settings


def middleware(app):
    @app.before_request
    def validate_request():
        print('-------------', request.args)

    @app.after_request
    def response_handler(response):
        response.headers["Access-Control-Allow-Origin"] = ",".join(settings.ALLOW_ORIGIN)
        response.headers["Access-Control-Allow-Methods"] = ",".join(settings.ALLOW_METHODS)
        response.headers["Access-Control-Allow-Credentials"] = settings.ALLOW_CREDENTIALS
        return response

